package opreation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOpreation implements IOpreation{
    @Override
    public void work(BookList booklist) {
        System.out.println("借阅图书");
        System.out.println("输入你要借阅的书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = booklist.getUsedsize();
        int i = 0;
        for (; i < size; i++) {
             Book book = booklist.getBooks(i);
             if(book.getName().equals(name)) {
                 break;
             }
        }
        if(i>=size) {
            System.out.println(name+"不存在，无法借阅");
            return;
        }
        Book book = booklist.getBooks(i);
        if(book.isBorrow()==false) {
            System.out.println("借阅成功,该书信息如下：");
            System.out.println(book);
            book.setBorrow(true);
            return;
        }
        System.out.println(name+"已被借阅");
    }
}
